package com.ruoyi.web.controller.social.examine;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.ExaminePlanDetail;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ExaminePlanDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: ruohao
 * @Date: 2023/9/3
 **/
@RestController
@RequestMapping("/social/examine/planDetail")
public class ExaminePlanDetailController extends BaseController {
    @Autowired
    private ExaminePlanDetailService examinePlanDetailService;
    @Log(title = "考核方案记录单", businessType = BusinessType.OTHER)
    @GetMapping("/list")
    public TableDataInfo list(ExaminePlanDetail examinePlanDetail)
    {
        startPage();
        List<ExaminePlanDetail> list = examinePlanDetailService.selectList(examinePlanDetail);
        return getDataTable((list));
    }


    @Log(title = "考核方案记录单All", businessType = BusinessType.OTHER)
    @GetMapping("/listAll")
    public TableDataInfo listAll(ExaminePlanDetail examinePlanDetail)
    {
        List<ExaminePlanDetail> list = examinePlanDetailService.selectList(examinePlanDetail);
        return getDataTable(list);
    }
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(examinePlanDetailService.selectById(id));
    }

    @Log(title = "考核方案记录单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody ExaminePlanDetail examinePlanDetail)
    {
        examinePlanDetail.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        Boolean result = examinePlanDetailService.create(examinePlanDetail);
        if (result) {
            return success();
        }
        return error();
    }

    @Log(title = "考核方案记录单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ExaminePlanDetail examinePlanDetail) {
        examinePlanDetail.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        Boolean result = examinePlanDetailService.update(examinePlanDetail);
        if (result) {
            return success();
        }
        return error();
    }

    @Log(title = "考核方案记录单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(examinePlanDetailService.deleteById(id));
    }




}
